Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lblTitle As System.Windows.Forms.Label Friend WithEvents btnFuel As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents TxtLocation As System.Windows.Forms.TextBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtPoints As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtPhilly As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents txtNYC As System.Windows.Forms.TextBox Friend WithEvents BtnGo As System.Windows.Forms.Button Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents TxtGas As System.Windows.Forms.TextBox Friend WithEvents Label9 As System.Windows.Forms.Label Friend WithEvents TxtCash As System.Windows.Forms.TextBox Friend WithEvents TxtRich As System.Windows.Forms.TextBox Friend WithEvents TxtDC As System.Windows.Forms.TextBox Friend WithEvents TxtBalt As System.Windows.Forms.TextBox Friend WithEvents CmbDest As System.Windows.Forms.ComboBox Friend WithEvents Label10 As System.Windows.Forms.Label Private Sub InitializeComponent() Me.lblTitle = New System.Windows.Forms.Label Me.btnFuel = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.TxtLocation = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.TxtPoints = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.TxtPhilly = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.TxtRich = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtDC = New System.Windows.Forms.TextBox Me.Label6 = New System.Windows.Forms.Label Me.TxtBalt = New System.Windows.Forms.TextBox Me.Label7 = New System.Windows.Forms.Label Me.txtNYC = New System.Windows.Forms.TextBox Me.BtnGo = New System.Windows.Forms.Button Me.Label8 = New System.Windows.Forms.Label Me.TxtGas = New System.Windows.Forms.TextBox Me.Label9 = New System.Windows.Forms.Label Me.TxtCash = New System.Windows.Forms.TextBox Me.CmbDest = New System.Windows.Forms.ComboBox Me.Label10 = New System.Windows.Forms.Label Me.SuspendLayout() ' 'lblTitle ' Me.lblTitle.AutoSize = True Me.lblTitle.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblTitle.Location = New System.Drawing.Point(48, 24) Me.lblTitle.Name = "lblTitle" Me.lblTitle.Size = New System.Drawing.Size(115, 23) Me.lblTitle.TabIndex = 0 Me.lblTitle.Text = "CSC 230 Toy" ' 'btnFuel ' Me.btnFuel.Location = New System.Drawing.Point(24, 328) Me.btnFuel.Name = "btnFuel" Me.btnFuel.TabIndex = 1 Me.btnFuel.Text = "Get Fuel" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(200, 328) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.TabIndex = 2 Me.BtnQuit.Text = "Quit" ' 'TxtLocation ' Me.TxtLocation.Location = New System.Drawing.Point(152, 152) Me.TxtLocation.Name = "TxtLocation" Me.TxtLocation.ReadOnly = True Me.TxtLocation.Size = New System.Drawing.Size(96, 22) Me.TxtLocation.TabIndex = 3 Me.TxtLocation.Text = "Philly" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(32, 152) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(112, 24) Me.Label1.TabIndex = 4 Me.Label1.Text = "Current Location" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(32, 120) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(112, 24) Me.Label2.TabIndex = 6 Me.Label2.Text = "Current Points" ' 'TxtPoints ' Me.TxtPoints.Location = New System.Drawing.Point(152, 120) Me.TxtPoints.Name = "TxtPoints" Me.TxtPoints.ReadOnly = True Me.TxtPoints.Size = New System.Drawing.Size(96, 22) Me.TxtPoints.TabIndex = 5 Me.TxtPoints.Text = "0" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(424, 96) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(72, 24) Me.Label3.TabIndex = 8 Me.Label3.Text = "Philly:" ' 'TxtPhilly ' Me.TxtPhilly.Location = New System.Drawing.Point(504, 96) Me.TxtPhilly.Name = "TxtPhilly" Me.TxtPhilly.ReadOnly = True Me.TxtPhilly.Size = New System.Drawing.Size(96, 22) Me.TxtPhilly.TabIndex = 7 Me.TxtPhilly.Text = "" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(424, 160) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(72, 24) Me.Label4.TabIndex = 10 Me.Label4.Text = "Baltimore:" ' 'TxtRich ' Me.TxtRich.Location = New System.Drawing.Point(504, 224) Me.TxtRich.Name = "TxtRich" Me.TxtRich.ReadOnly = True Me.TxtRich.Size = New System.Drawing.Size(96, 22) Me.TxtRich.TabIndex = 9 Me.TxtRich.Text = "" ' 'Label5 ' Me.Label5.Location = New System.Drawing.Point(424, 192) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(72, 24) Me.Label5.TabIndex = 12 Me.Label5.Text = "DC:" ' 'TxtDC ' Me.TxtDC.Location = New System.Drawing.Point(504, 192) Me.TxtDC.Name = "TxtDC" Me.TxtDC.ReadOnly = True Me.TxtDC.Size = New System.Drawing.Size(96, 22) Me.TxtDC.TabIndex = 11 Me.TxtDC.Text = "" ' 'Label6 ' Me.Label6.Location = New System.Drawing.Point(424, 224) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(72, 24) Me.Label6.TabIndex = 14 Me.Label6.Text = "Richmond:" ' 'TxtBalt ' Me.TxtBalt.Location = New System.Drawing.Point(504, 160) Me.TxtBalt.Name = "TxtBalt" Me.TxtBalt.ReadOnly = True Me.TxtBalt.Size = New System.Drawing.Size(96, 22) Me.TxtBalt.TabIndex = 13 Me.TxtBalt.Text = "" ' 'Label7 ' Me.Label7.Location = New System.Drawing.Point(424, 128) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(72, 24) Me.Label7.TabIndex = 16 Me.Label7.Text = "NYC:" ' 'txtNYC ' Me.txtNYC.Location = New System.Drawing.Point(504, 128) Me.txtNYC.Name = "txtNYC" Me.txtNYC.ReadOnly = True Me.txtNYC.Size = New System.Drawing.Size(96, 22) Me.txtNYC.TabIndex = 15 Me.txtNYC.Text = "" ' 'BtnGo ' Me.BtnGo.Location = New System.Drawing.Point(112, 328) Me.BtnGo.Name = "BtnGo" Me.BtnGo.TabIndex = 17 Me.BtnGo.Text = "Go" ' 'Label8 ' Me.Label8.Location = New System.Drawing.Point(32, 184) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(112, 24) Me.Label8.TabIndex = 19 Me.Label8.Text = "Current Gas:" ' 'TxtGas ' Me.TxtGas.Location = New System.Drawing.Point(152, 184) Me.TxtGas.Name = "TxtGas" Me.TxtGas.ReadOnly = True Me.TxtGas.Size = New System.Drawing.Size(96, 22) Me.TxtGas.TabIndex = 18 Me.TxtGas.Text = "10" ' 'Label9 ' Me.Label9.Location = New System.Drawing.Point(32, 216) Me.Label9.Name = "Label9" Me.Label9.Size = New System.Drawing.Size(112, 24) Me.Label9.TabIndex = 21 Me.Label9.Text = "Current Cash:" ' 'TxtCash ' Me.TxtCash.Location = New System.Drawing.Point(152, 216) Me.TxtCash.Name = "TxtCash" Me.TxtCash.ReadOnly = True Me.TxtCash.Size = New System.Drawing.Size(96, 22) Me.TxtCash.TabIndex = 20 Me.TxtCash.Text = "10" ' 'CmbDest ' Me.CmbDest.Items.AddRange(New Object() {"Philly", "NYC", "Baltimore", "DC", "Richmond"}) Me.CmbDest.Location = New System.Drawing.Point(152, 272) Me.CmbDest.Name = "CmbDest" Me.CmbDest.Size = New System.Drawing.Size(96, 24) Me.CmbDest.TabIndex = 22 ' 'Label10 ' Me.Label10.Location = New System.Drawing.Point(32, 272) Me.Label10.Name = "Label10" Me.Label10.Size = New System.Drawing.Size(112, 24) Me.Label10.TabIndex = 23 Me.Label10.Text = "Next Destination:" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.BackColor = System.Drawing.Color.Red Me.ClientSize = New System.Drawing.Size(696, 384) Me.Controls.Add(Me.Label10) Me.Controls.Add(Me.CmbDest) Me.Controls.Add(Me.Label9) Me.Controls.Add(Me.TxtCash) Me.Controls.Add(Me.Label8) Me.Controls.Add(Me.TxtGas) Me.Controls.Add(Me.BtnGo) Me.Controls.Add(Me.Label7) Me.Controls.Add(Me.txtNYC) Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.TxtBalt) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.TxtDC) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.TxtRich) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.TxtPhilly) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.TxtPoints) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.TxtLocation) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.btnFuel) Me.Controls.Add(Me.lblTitle) Me.Name = "Form1" Me.Text = "Silly Game" Me.ResumeLayout(False) End Sub #End Region Const UPPER As Integer = 9 Const LOWER As Integer = 1 Const gasPrice As Double = 2.0 Const gasToTravel As Double = 1.0 Private Function randPts() As Integer Dim rand As Integer rand = Convert.ToInt32((UPPER - LOWER + 1) * Rnd() + LOWER) Return rand End Function Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim rand As Integer TxtPhilly.Text = "0" rand = randPts() txtNYC.Text = rand.ToString("n0") rand = randPts() TxtBalt.Text = rand.ToString("n0") rand = randPts() TxtDC.Text = rand.ToString("n0") rand = randPts() TxtRich.Text = rand.ToString("n0") End Sub Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click Dim newPts As Integer Dim pts As Integer Dim gasAvail As Double gasAvail = Convert.ToDouble(TxtGas.Text) If gasAvail >= gasToTravel Then pts = Convert.ToInt32(TxtPoints.Text) Select Case CmbDest.Text Case "Philly" newPts = Convert.ToInt32(TxtPhilly.Text) TxtLocation.Text = "Philly" TxtPhilly.Text = "0" txtNYC.Text = Convert.ToString(randPts()) TxtBalt.Text = Convert.ToString(randPts()) TxtDC.Text = Convert.ToString(randPts()) TxtRich.Text = Convert.ToString(randPts()) Case "NYC" newPts = Convert.ToInt32(txtNYC.Text) TxtLocation.Text = "NYC" txtNYC.Text = "0" TxtPhilly.Text = Convert.ToString(randPts()) TxtBalt.Text = Convert.ToString(randPts()) TxtDC.Text = Convert.ToString(randPts()) TxtRich.Text = Convert.ToString(randPts()) Case "Baltimore" newPts = Convert.ToInt32(TxtBalt.Text) TxtLocation.Text = "Baltimore" TxtBalt.Text = "0" txtNYC.Text = Convert.ToString(randPts()) TxtPhilly.Text = Convert.ToString(randPts()) TxtDC.Text = Convert.ToString(randPts()) TxtRich.Text = Convert.ToString(randPts()) Case "DC" newPts = Convert.ToInt32(TxtDC.Text) TxtLocation.Text = "DC" TxtDC.Text = "0" txtNYC.Text = Convert.ToString(randPts()) TxtBalt.Text = Convert.ToString(randPts()) TxtPhilly.Text = Convert.ToString(randPts()) TxtRich.Text = Convert.ToString(randPts()) Case "Richmond" newPts = Convert.ToInt32(TxtRich.Text) TxtLocation.Text = "Richmond" TxtRich.Text = "0" txtNYC.Text = Convert.ToString(randPts()) TxtBalt.Text = Convert.ToString(randPts()) TxtDC.Text = Convert.ToString(randPts()) TxtPhilly.Text = Convert.ToString(randPts()) End Select pts = pts + newPts TxtPoints.Text = Convert.ToString(pts) gasAvail = gasAvail - gasToTravel TxtGas.Text = gasAvail.ToString("n1") Else MsgBox("not enough gas to travel") End If End Sub Private Sub btnFuel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFuel.Click Dim moneyAvail As Double Dim gasAvail As Double moneyAvail = Convert.ToDouble(TxtCash.Text) gasAvail = Convert.ToDouble(TxtGas.Text) If moneyAvail >= gasPrice Then moneyAvail = moneyAvail - gasPrice gasAvail = gasAvail + 1 TxtCash.Text = moneyAvail.ToString("n2") TxtGas.Text = gasAvail.ToString("n1") Else MsgBox("not enough money to buy gas") End If End Sub End Class